<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>切换</title>
    <style>
        p{
            font-size: 20px;
            color: red;
        }
        .automatic{
            right: 10px;
            top: 10px;
            width: 600px;
            height: 600px;
        }
        #auto{
            transition: all 1s;
        }
    </style>
</head>
<body>
    <div>
        <p>这是手动切换</p>
        <img src="01.jpg" alt="" id="imgs"><br>
        <input type="button" value="上一张" id="pver">
        <input type="button" value="下一张" id="next">
    </div>
    <div class="automatic">
        <p>这是自动切换</p>
        <img src="01.jpg" alt="" id="auto">
    </div>
    
    <script>
        var inputObj_next = document.getElementById('next')
        var inputObj_pver = document.getElementById('pver')
        var max=3,min=1,now=1;      
        inputObj_next.onclick = function(){
            if(now === max){
                imgObj = document.getElementById('imgs')
                imgObj.setAttribute('src','01.jpg');
                now = min;
            }
            else{
                now++;
                imgObj = document.getElementById('imgs')
                imgObj.setAttribute('src','0'+now+'.jpg');
            }
            
        }
        inputObj_pver.onclick = function(){
            if(now === min){
                imgObj = document.getElementById('imgs')
                imgObj.setAttribute('src','03.jpg');
                now = max;
            }
            else{
                now--;
                imgObj = document.getElementById('imgs')
                imgObj.setAttribute('src','0'+now+'.jpg');
            }
        }

        img_auto = document.getElementById('auto')
        var i=1,time=null;
        setInterval(function(){
            if(i === max){
                img_auto.setAttribute('src','01.jpg')
                i = min;
            }
            else{
                i++;
                img_auto.setAttribute('src','0'+i+'.jpg');
            }
        },2000)

    </script>
</body>
</html>